
cap log using "Loanshark_Manuscript_Tables-hagemann.log", replace

*******************************
*
* Perform Permutation Approach in Hagemann (2019) for Estimates in Table 3 in Manuscript
*
*******************************

use loanshark_data_final, clear

gen coef = .
gen fake = 0
gen ydum = .
replace ydum = 0 if _n==1
gen enforced = 0 + 1*(_n>5) if _n<9
gen trend = _n

foreach v in rate_pct loan loanasked lendrate totalpaid latefee_share default howrepayn3 howrepayn2 lenderrequestwork conscription repayendD {
di "**************OLS: `v' *************************"
quietly xi: reg `v' i.year
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
			centile coef, centile(2.5 97.5)
di "**************FE_Lender: `v' *************************"			
quietly xi: areg `v' i.year, abs(sharkid5)
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
				centile coef, centile(2.5 97.5)
				
di "**************FE_Borrower: `v' *************************"
quietly xi: areg `v' i.year, abs(id)
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
			centile coef, centile(2.5 97.5)
di "**************FE_Borrower_Lender: `v' *************************"
quietly xi: areg `v' i.year, abs(shark5_bor)
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
			centile coef, centile(2.5 97.5)
reg `v' enforcement
areg `v' enforcement, abs(sharkid5)
areg `v' enforcement, abs(id)
areg `v' enforcement, abs(shark5_bor)
}


preserve
	
	keep if repayfull ==0 | repayend<2

foreach ii in noforce remind  {

di "**************OLS: `ii' *************************"
quietly	xi: reg `ii' i.year
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
			centile coef, centile(2.5 97.5)
di "**************FE_Lender: `ii' *************************"
quietly	xi: areg `ii' i.year, abs(sharkid5)
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
			centile coef, centile(2.5 97.5)
di "**************FE_Borrower: `ii' *************************"
quietly	xi: areg `ii' i.year, abs(id)
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
			centile coef, centile(2.5 97.5)
di "**************FE_Borrower_Lender: `ii' *************************"
quietly	xi: areg `ii' i.year, abs(shark5_bor)
	forvalues x = 10/16 {
		quietly replace ydum = _b[_Iyear_20`x'] if _n==`x'-8
		}
		reg ydum enforced
		reg ydum enforced trend
		scalar count = 1
			forvalues i = 1/6 {
				scalar jm = `i'+1
				forvalues j = `=jm'/7 {
					scalar km = `j' + 1
					forvalues k = `=km'/8 {
					quietly replace fake = 1 if (_n==`i'|_n==`j'|_n==`k')
					quietly reg ydum fake
					scalar count = count + 1
					quietly replace coef = _b[fake] if _n==count
					quietly replace fake = 0
					}
					}
					}
			centile coef, centile(2.5 97.5)
	reg `ii' enforcement
	areg `ii' enforcement, abs(sharkid5)
	areg `ii' enforcement, abs(id)
	areg `ii' enforcement, abs(shark5_bor)
	}

	
log close

